package cn.tedu.mimall.product.service.impl;

import cn.tedu.mimall.product.mapper.OrderMapper;
import cn.tedu.mimall.product.pojo.entity.Order;
import cn.tedu.mimall.product.pojo.vo.OrderStandardVO;
import cn.tedu.mimall.product.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * 处理商品订单的业务实现类
 *
 * @author 无所事事的小鱼人
 * @version 0.0.1
 */
@Service
@Slf4j
public class OrderServiceImpl implements IOrderService {

    @Autowired
    OrderMapper orderMapper;

    @Override
    public void insert(OrderStandardVO orderStandardVO) {
        log.debug("开始处理【添加订单】的业务，参数：{}",orderStandardVO);
        Order order=new Order();
        BeanUtils.copyProperties(orderStandardVO,order);
        // 自1970年1月1日至今的毫秒数
        long time = System.currentTimeMillis();
        String orderNumber=time+""+order.getUserId();
        int length = orderNumber.length();
        if(length>24){
            orderNumber=orderNumber.substring(0,24);
        }
        if(orderNumber.length()<24){
            orderNumber=orderNumber+(new Random().nextInt(900)+100);
        }
    }
}
